﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Excel = Microsoft.Office.Interop.Excel;
using System.Data;
using ZLDC.Topo.BLL.Estate;
using ZLDC.Common.Estate;
namespace ZLDC.Estate.Quantify.Report
{
    public partial class lp_Share_Excel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


        }
        protected void Button4_Click(object sender, EventArgs e)
        {

            if (FuloadExcelFile.PostedFile.FileName == "")
            {
                Response.Write("<script language=javascript>alert('请选择要上传的模版！');</script>");
                return;
            }
            string fileExt = System.IO.Path.GetExtension(FuloadExcelFile.FileName);
            if (fileExt != ".xls" && fileExt != ".xlsx")//必须是EXCEL文件
            {
                return;
            }
            string filepath = FuloadExcelFile.PostedFile.FileName;//文件路径

            DataTable dt = new DataTable();

            dt = ZLDC.Topo.BLL.Estate.lp_Basis.CallExcel(filepath);//返回EXCEL文件的数据

            try
            {
                if(dt.Rows.Count>0){
                ZLDC.Topo.BLL.Estate.lp_Share.InsertSQLServer(dt, "lp_Share", _Utility.GetInfoBySession().m_sUserID, _Utility.GetInfoBySession().m_sDeptID, _Utility.GetInfoBySession().m_sDeptName, _Utility.GetInfoBySession().m_sUserName);
                Response.Write("<script >alert('导入成功！');window.location.href=location.href;</script>");
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script >alert('导入失败！" + ex.ToString() + "');window.location.href=location.href;</script>");
            }
        }


        protected void Button5_Click(object sender, EventArgs e)
        {
            ZLDC.Topo.BLL.Estate.lp_Share.DownloadFile("市场占有率.xls", Page);
        }

    }
}
